package singletontest;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 使用静态内置类实现单例模式
 *
 * @author liuziyang
 * @create 2019-10-14 20:37
 */
public class SingletonTest7 {
    public static SingletonTest7 getInstance() {
        return SingletonTest7Handle.getInstance();
    }

    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(SingletonTest7.getInstance().hashCode());
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(SingletonTest7.getInstance().hashCode());
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(SingletonTest7.getInstance().hashCode());
            }
        }).start();
    }

    public static class SingletonTest7Handle {
        private static SingletonTest7 myObject = new SingletonTest7();

        public static SingletonTest7 getInstance() {
            return myObject;
        }
    }
}
